/**
 * Created by Admin on 2018/1/22.
 */
define(function(require,exports,module){
    var commonPaging = require("../common/commonPagingCq.js");
    var template = require("template");
    require("../common/My97DatePicker1/WdatePicker.js");
    require("../seajs-init.js");
    var p ;


    var obligeePM  = {
        init:function(keyUrl,exportUrl,tpl){
            this.initPage(keyUrl,tpl);
            this.getList();
        },
        initPage:function(keyUrl,tpl){
            setTimeout(function(){
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: keyUrl,
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            },500)
        },
        getList: function () {
            /*获取专利类型*/
            $.ajax({
                url: window.jkconfig.webapiurlv + "applychange/param",
                success: function (data) {
                    if (data.code == 0) {
                        var typeHtml = '<label class="ptmt-collction-s-a-label commonColor patType">专利类型：</label>';
                        /*遍历data.patTypes,获取区域列表*/
                        if (data.patTypes.length > 0) {
                            for (var i = 0; i < data.patTypes.length; i++) {
                                typeHtml += '<input type="checkbox" name="patType" value="'+data.patTypes[i].value+'" checked><label class="ptmt-collction-s-t-b-lable">'+ data.patTypes[i].name +'</label>';
                            }
                            $("#searchType").html(typeHtml);
                        }
                    } else {
                        $.showErr("获取专利类型列表失败!");
                    }
                }
            });
            /*获取失效原因列表*/
            if($(".ptmt-collction-search-invalid").length > 0 ){
                $.ajax({
                    url: window.jkconfig.webapiurlv + "invalidAnalysis/param",
                    async:false,
                    success: function (data) {
                        if (data.code == 0) {
                            var invalidHtml = '<label class="ptmt-collction-s-a-label commonColor patType">失效原因：</label>';
                            /*遍历data.patTypes,获取区域列表*/
                            for(var key in data.invalidReason){
                                invalidHtml += '<input type="checkbox" name="invalidReason" value="'+key+'" checked><label class="ptmt-collction-s-t-b-lable">'+data.invalidReason[key]+'</label>';
                            }
                            $(".ptmt-collction-search-invalid").html(invalidHtml);
                        } else {
                            $.showErr("获取失效原因列表失败!");
                        }
                    }
                });
            }
        },
        bindEvent:function(keyUrl,exportUrl,tpl){
            var self = this;
            $("body").on("click",".btnSearch",function(){
               if($("#startDate").val() != "" || $("#endDate").val() != ""){
                   $(".patent-dataRange").hide();
               }else{
                   $(".patent-dataRange").show();
               }
                self.getPageList(keyUrl,tpl);
            }).on("click",".btnExport",function(){
                window.location.href = exportUrl+ "?pageNumber=1&pageSize=5000"+"&"+api_key+"="+token;
            })
        },
        getPageList:function(keyUrl,tpl){
            /*权利人*/
            $("[name=]")
            if($("#Js_fs_paging").css("display") == "block"){
                p.page.destroy && p.page.destroy();
                $("[name=pageNumber]").val(1);
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: keyUrl,
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }else{
                p=new commonPaging({
                    htmlContainer: "#Js_page_content",
                    pageContainer: "#Js_fs_paging",
                    url: keyUrl,
                    tpl:tpl,
                    data:$("#searchForm").serialize()
                });
                p.init();
            }
        },
    }

    module.exports = obligeePM;



})